//
//  ASJSkillNoLoopSkill.m
//  ASJ001
//
//  Created by zephyrhan on 11/26/11.
//  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//

#import "ASJSkillNoLoopSkill.h"


@implementation ASJSkillNoLoopSkill

- (id)initWithSkillName:(NSString*)name frameCount:(NSInteger)count inStage:(ASJStage*)stage {
    return  [self initWithSkillName:name frameCount:count comboTarget:nil action:nil inStage:stage];
}


- (id)initWithSkillName:(NSString*)name frameCount:(NSInteger)count comboTarget:(id)target action:(SEL)action inStage:(ASJStage*)stage { 
    if ((self = [super initWithSkillName:name frameCount:count comboTarget:target action:action inStage:stage])) {
        skillPriority = 1;
    }
    
    return  self;
}

- (void)loadSkillSpriteToLayer:(CCLayer*)layer {
    skillBatchNode = [CCSpriteBatchNode batchNodeWithFile:[NSString stringWithFormat:@"%@.png", skillName]]; 
    [layer addChild:skillBatchNode];
    
    NSMutableArray* skillFrames = [NSMutableArray array];
    CCSpriteFrameCache* frameCache = [CCSpriteFrameCache sharedSpriteFrameCache];
    [frameCache addSpriteFramesWithFile:[NSString stringWithFormat:@"%@.plist", skillName]];
    for(int i = 0; i < frameCount; ++i) { 
        [skillFrames addObject:[frameCache spriteFrameByName:[NSString stringWithFormat:@"%@000%d.png", skillName, i]]];
    }
    CCAnimation* ani = [CCAnimation animationWithFrames:skillFrames delay:0.1f];
    
    if (comboTarget == nil) {
        CCCallFunc*  effect = [CCCallFunc actionWithTarget:self selector:@selector(skillEffect)];
        CCSequence* seq = [CCSequence actions:[CCAnimate actionWithAnimation:ani restoreOriginalFrame:YES], effect, nil];
        skillAnimation = [seq retain];
    } else {
        CCCallFunc*  effect = [CCCallFunc actionWithTarget:comboTarget selector:comboAction];
        CCSequence* seq = [CCSequence actions:[CCAnimate actionWithAnimation:ani restoreOriginalFrame:YES], effect, nil];
        skillAnimation = [seq retain];
    }
    
    skillSprite = [[CCSprite spriteWithSpriteFrame:[frameCache spriteFrameByName:[NSString stringWithFormat:@"%@0000.png", skillName]]] retain];
}


- (void)skillEffect {
    [super skillEffect];
}


@end
